package com.Customer.service;

import com.Customer.entity.Customer;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public interface CustomerService {

    @CircuitBreaker(name = "customerService", fallbackMethod = "addCustomerFallback")
    boolean doAddCustomerInfo(Customer customer);

    @CircuitBreaker(name = "customerService", fallbackMethod = "modifyCustomerFallback")
    boolean doModifyCustomerInfo(Customer customer);

    @CircuitBreaker(name = "customerService", fallbackMethod = "deleteCustomerFallback")
    boolean doDeleteCustomerInfo(Customer customer);

    @CircuitBreaker(name = "customerService", fallbackMethod = "getCustomerInfoFallback")
    Customer doGetCustomerInfo(Customer customer);

    @CircuitBreaker(name = "customerService", fallbackMethod = "getCustomerInfoListFallback")
    List<Customer> doGetCustomerInfoList();

    @CircuitBreaker(name = "customerService", fallbackMethod = "queryCustomerInfoListFallback")
    List<Customer> doQueryCustomerInfoList(Customer customer);

    // 定义 fallback 方法（添加详细日志）
    default boolean addCustomerFallback(Customer customer, Throwable t) {
        System.err.println("【Service熔断】添加客户降级：" + t.getClass().getName() + " - " + t.getMessage());
        return false;
    }

    default boolean modifyCustomerFallback(Customer customer, Throwable t) {
        System.err.println("【Service熔断】修改客户降级：" + t.getClass().getName() + " - " + t.getMessage());
        return false;
    }

    default boolean deleteCustomerFallback(Customer customer, Throwable t) {
        System.err.println("【Service熔断】删除客户降级：" + t.getClass().getName() + " - " + t.getMessage());
        return false;
    }

    default Customer getCustomerInfoFallback(Customer customer, Throwable t) {
        System.err.println("【Service熔断】获取客户降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }

    default List<Customer> getCustomerInfoListFallback(Throwable t) {
        System.err.println("【Service熔断】获取列表降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }

    default List<Customer> queryCustomerInfoListFallback(Customer customer, Throwable t) {
        System.err.println("【Service熔断】查询列表降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }
}